<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
 <%@ page import="java.util.*, com.dr.pojo.*" %>

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Insert title here</title>
<style type="text/css">
	*{
		margin:0;
		padding:0;
		font-size:14px;
	}
	div{
		width:1000px;
		margin:0 auto;
		margin-top:10px;
	}
	table{
		width:100%;
	}
	.table-list{
		border:1px solid red;
		border-collapse:collapse;
	}
	.table-list th,td{
		border:1px solid gray;
		padding:5px;
		text-align:center;
	}
	h4{
		margin-bottom: 5px;
	}
</style>

<script type="text/javascript" src="/lib/jquery-3.4.1.js"></script>
<script type="text/javascript">
	$(function(){
		$('#btnAdd').click(function(){
			$("#frm").attr("action","/um/toAdd")
			$("#frm").submit();
		});
	});
	function delUser(id,name){
		var msg = "此操作将删除用户："+name;
		msg +="\n单击确认，将执行删除。单击取消，则撤销删除。";
		if(confirm(msg)==true){
			//执行删除
			var frm = document.getElementById('frm');
			frm.action = "/um/doDelete?id="+id;
			frm.submit();
		}
	}
</script>

</head>
<body>

  <div >
  
	<h1>欢迎！！！</h1>
	
	<h4>系统用户查询</h4>
	<form id="frm" action="/um/userListByName" method="post"> <!-- 此处必须为post，不然"/um/doDelete?id="+id的id传不过去 -->
		<input type="search" placeholder="  请输入用户名"  name="txtQuery">
		<input type="submit"   value="查询用户"   >
		<input type="button"   value="增加用户" id="btnAdd">
	</form>
	 <hr>	
	<h4>系统用户列表</h4>
	<table class="table-list">
		<tr>
			<th>系统账户</th>
			<th>用户名</th>
			<th>岗位</th>
			<th>部门</th>
			<th>操作</th>			
		</tr>
		
<%
	
	List<User> list = (List)request.getAttribute("userList");
	//out.println(list);测试
	for(User user : list){
		//out.println(user);
%>		
		<tr>
			<td><%=user.getAccount() %></td>
			<td><%=user.getName() %></td>
			<td><%=user.getJob() %></td>
			<td><%=user.getDeptId() %></td>
			<td>
				<a href="/um/toUpdate?id=<%=user.getId()%>">修改</a>
				<%-- <a href="/um/doDelete?id=<%=user.getId()%>">删除</a> --%>
				<a href="javascript:delUser(<%=user.getId()%>,'<%=user.getName()%>')">删除</a>
			</td>
		</tr>
<%
	}
%>		
	</table>
  </div>
</body>
</html>
    